package com.rfid.assistant.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;

import android.Manifest;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.provider.Settings;
import android.view.View;

import com.rfid.assistant.R;
import com.rfid.socketio.SocketIoInstance;

public class FunctionActivity extends AppCompatActivity {
    private int REQ_PERMISSION_CODE = 100;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_function);
        askForPermissions();
        ActivityCompat.requestPermissions(this,new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
                100);
        SocketIoInstance.INSTANCE.init(this,"",false);
    }

    public void sl(View view) {
        HomeActivity.startActivity(this);
    }

    public void send(View view) {
        HomeActivity.startActivity(this,true);
    }


    public void server(View view) {
        ServerActivity.startActivity(this);
    }

    public void askForPermissions() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
            if (!Environment.isExternalStorageManager()) {
                Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
                intent.setData(Uri.parse("package:" + getPackageName()));
                startActivityForResult(intent, REQ_PERMISSION_CODE);
            }
        }
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        SocketIoInstance.INSTANCE.release();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        System.out.println("FunctionActivity onDestroy");
    }
}